<template>
    <div>
        <mbx />
        <el-card>
            <!-- 搜索 -->
            <el-row :gutter="20">
                <el-col :span="10">
                    <el-input placeholder="请输入内容" v-model="query.query" class="input-with-select">
                        <el-button slot="append" icon="el-icon-search" @click="getOrderList"></el-button>
                    </el-input>
                </el-col>
            </el-row>
            <!-- 表格 -->
            <el-table :data="orderList" border style="width: 100%">
                <el-table-column type="index" label="#">
                </el-table-column>
                <el-table-column prop="order_id" label="订单编号">
                </el-table-column>
                <el-table-column prop="order_price" label="订单价格">
                </el-table-column>
                <el-table-column prop="date" label="是否付款">
                    <el-button type="primary" icon="el-icon-edit" size="mini">未付款</el-button>
                </el-table-column>
                <el-table-column prop="is_send" label="是否发货">
                </el-table-column>
                <el-table-column prop="create_time" label="下单时间">
                    <template slot-scope="scope">
                        {{ scope.row.create_time | dateFormate }}
                    </template>
                </el-table-column>
                <el-table-column prop="address" label="操作">
                    <template slot-scope="scope">
                        <el-button type="primary" icon="el-icon-edit" size="mini" @click="changC"></el-button>
                        <el-button type="success" icon="el-icon-check" size="mini"
                            @click="getWuLiu(scope.row.order_id)"></el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 修改地址对话框 -->
            <el-dialog title="修改地址" :visible.sync="changeCity" width="700px">
                <el-form :model="form">
                    <el-form-item label="省/市/县" label-width="80px">
                        <!-- 级联选择器 -->
                        <el-cascader v-model="value" :options="options" @change="handleChange"></el-cascader>
                    </el-form-item>
                    <el-form-item label="修改地址" label-width="80px">
                        <el-input v-model="form.cityName" autocomplete="off"></el-input>
                    </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="changeCity = false">取 消</el-button>
                    <el-button type="primary" @click="changeCity = false">确 定</el-button>
                </div>
            </el-dialog>
            <!-- 物流信息对话框 -->
            <el-dialog title="物流信息" :visible.sync="wuLiu">
                <!-- 时间线 -->
                <el-timeline :reverse="reverse">
                    <el-timeline-item v-for="(activity, index) in activities" :key="index" :timestamp="activity.ftime">
                        {{ activity.context }}
                    </el-timeline-item>
                </el-timeline>
            </el-dialog>
            <!-- 分页 -->
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                :current-page="query.pagenum" :page-sizes="[3, 5, 7, 9]" :page-size="query.pagesize"
                layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </el-card>
    </div>
</template>

<script>
/**
 * 名门望组：黄小波
 * 对应模块：订单管理模块
 * 思路分析
 * 1.接口请求：接口文档：订单数据列表，请求路径：orders，请求方法：get，请求参数：query、pageNum、pagesize
 * 2.样式布局：订单主页的面包屑导航组件的引入，element-ui框架的表格进行订单数据的渲染，底部分页组件
 * 3.功能分析：搜索功能--输入框搜索关键字查询订单数据。
 *          修改地址--点击修改地址按钮弹出UI框架Dialog对话框，级联选择器数据绑定。    
 *          物流信息--点击物流按钮弹出UI框架Dialog对话框，对话框里有UI框架时间线
 *          分页功能--UI框架分页组件引入，参数绑定，页码、条数改变触发对应函数将返回值赋值
*/
import mbx from '@/components/mbx.vue'
import { orderList } from '@/utils/order/api'
import { orderWu } from '@/utils/order/api'
export default {
    components: { mbx },
    data() {
        return {
            query: {
                query: '',
                pagenum: 1,
                pagesize: 5,
            },
            total: 0,
            orderList: [],
            /* 改地址 */
            changeCity: false,
            form: {
                cityName: '',
            },
            value: [],
            options: [
                {
                    value: '河北',
                    label: '河北',
                    children: [
                        {
                            value: '石家庄',
                            label: '石家庄',
                            children: [
                                {
                                    value: '秦皇岛',
                                    label: '秦皇岛'
                                }
                            ]
                        }
                    ]
                },
                {
                    value: '天津',
                    label: '天津',
                    children: [
                        {
                            value: '石家庄',
                            label: '石家庄',
                            children: [
                                {
                                    value: '秦皇岛',
                                    label: '秦皇岛'
                                }
                            ]
                        }
                    ]
                },
                {
                    value: '内蒙古',
                    label: '内蒙古',
                    children: [
                        {
                            value: '石家庄',
                            label: '石家庄',
                            children: [
                                {
                                    value: '秦皇岛',
                                    label: '秦皇岛'
                                }
                            ]
                        }
                    ]
                },
                {
                    value: '陕西',
                    label: '陕西',
                    children: [
                        {
                            value: '石家庄',
                            label: '石家庄',
                            children: [
                                {
                                    value: '秦皇岛',
                                    label: '秦皇岛'
                                }
                            ]
                        }
                    ]
                },
            ],
            /* 物流信息 */
            wuLiu: false,
            reverse: true,
            activities: [],
        }
    },
    mounted() {
        this.getOrderList();
    },
    methods: {
        /* 获取订单列表数据 */
        async getOrderList() {
            let res = await orderList(this.query);
            this.orderList = res.data.goods;
            this.total = res.data.total;
        },
        /* 修改地址 */
        changC() {
            this.changeCity = true;
        },
        /* 级联选择器 */
        handleChange(value) {
            console.log(value);
        },
        /* 物理信息 */
        async getWuLiu(id) {
            this.wuLiu = true;
            let res = await orderWu(id);
            res.data.forEach((item) => {
                this.activities.push(item);
            })
        },
        /* 当前页改变触发 */
        handleCurrentChange(num) {
            this.query.pagenum = num;
            this.getOrderList();
        },
        /* 每页条数发生改变 */
        handleSizeChange(size) {
            this.query.pagesize = size;
            this.getOrderList();
        },
    },
}
</script>

<style lang="scss" scoped>

</style>